//
//  ExceptionalView.m
//  dyseller
//
//  Created by 红喇叭 on 2017/11/13.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "ExceptionalView.h"

@implementation ExceptionalView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = UIColorFromRGB(0xf3f3f3);
        [self initView];
    }
    return  self;
}
- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    [self removeAllSubViews];
    [self initView];
}

- (void)initView{
    
   // UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H*2/3)];
//    backView.center = self.center;
//    backView.backgroundColor = self.backgroundColor;
//    [self addSubview:backView];
    UIImage *imageV = [UIImage imageNamed:@"edit_note3_default.png"];
    UIImageView *exImg = [[UIImageView alloc] initWithFrame:CGRectMake((self.width-imageV.size.width)/2,(self.height-imageV.size.height)/2-100, imageV.size.width, imageV.size.height)];
    exImg.image = imageV;
    [self addSubview:exImg];
    
    UILabel *hintLab = [[UILabel alloc] initWithFrame:CGRectMake(0, exImg.bottom+GETHEIGHT(60), self.width, 20)];
    hintLab.text = @"网络加载异常，请再试一次";
    hintLab.textColor = kGrayColor;
    hintLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:hintLab];
    
    UIButton *refreshBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width/4, hintLab.bottom+GETHEIGHT(60), self.width/2, 30)];
    [refreshBtn setTitle:@"重新加载" forState:0];
    [refreshBtn setTitleColor:MianRedColor forState:0];
    refreshBtn.titleLabel.font = font14;
    [refreshBtn setBackgroundImage:[UIImage imageNamed:@"edit_button3_default_nor"] forState:0];
    [refreshBtn addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:refreshBtn];
    
}

- (void)refreshAction{
    if([_delegate respondsToSelector:@selector(buttonAction)]){
        [_delegate buttonAction];
    }
}

@end
